﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Gedea.WinForm.Helpers;
using Gedea.WinForm.Forms.Common;
using Gedea.Model.Entities;
using Gedea.Service.Services;
using Gedea.Service;

namespace Gedea.WinForm.Forms.Company
{
    public partial class AddEdit : BaseForm
    {
        public delegate void Deleg1();
        public delegate void Deleg2(User user);

        #region Ctr
        public static AddEdit Instance
        {
            get { return ViewLocator<AddEdit>.Instance; }
        }

        private AddEdit()
        {
            InitializeComponent();
        }
        #endregion

        private void AddEdit_Load(object sender, EventArgs e)
        {
            UserControls.CompanyControl editCompany = new UserControls.CompanyControl(new Deleg1(CloseApp), new Deleg2(AddUser), true);
            panel1.Controls.Add(editCompany);
        }

        private void AddEdit_FormClosed(object sender, FormClosedEventArgs e)
        {
            ViewLocator<AddEdit>.CloseInstance = null;
        }

        private void CloseApp()
        {
            this.Close();
        }

        private void AddUser(User user)
        {
            new UserService().Update(user);

            MessageBox.Show("Su usuario se ha actualizado satisfactoriamente");

            this.Close();
        }
    }
}
